package com.example.mybatisplus.pojo;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.util.UUID;

/**
 * 接口响应对象
 *
 * @author heshengfu1211
 * @since 2021-11-28
 */
@Data
public class ResponseVo implements Serializable {

    private String uuid;

    private int status;

    private String message;

    private Object data;

    public ResponseVo() {
        this.uuid = UUID.randomUUID().toString();
    }

    public ResponseVo(int status, String message) {
        this.uuid = UUID.randomUUID().toString();
        this.status = status;
        this.message = message;
    }

    public static ResponseVo success(Object data){
        ResponseVo responseVo = new ResponseVo(HttpStatus.OK.value(), HttpStatus.OK.name());
        responseVo.setData(data);
        return responseVo;
    }

    public static ResponseVo success(Object data, String message){
        ResponseVo responseVo = new ResponseVo(HttpStatus.OK.value(), message);
        responseVo.setData(data);
        return responseVo;
    }

    public static ResponseVo error(String message){
        ResponseVo responseVo = new ResponseVo(HttpStatus.INTERNAL_SERVER_ERROR.value(), message);
        return responseVo;
    }

    public static ResponseVo error(int status, String message){
        ResponseVo responseVo = new ResponseVo(status, message);
        return responseVo;
    }
}
